#ifndef RSSFACTORY_H
#define RSSFACTORY_H

#include <QObject>
#include <QDebug>
#include <QString>
#include <QList>
#include <QThread>
#include <QtNetwork>
#include <QWebView>
#include <QDomElement>

#include <cstdio>
#include <cstdlib>
#include <cstring>

//#include "rssfeed.h"

class RssFeed;


namespace RssgTypes {

	enum FeedType {
		FEED_UNKNOWN = 1000,
		FEED_RSS = 1001,
		FEED_ATOM = 1002
	};

}


class RssFactory {

	private:
        RssFactory() { }
        ~RssFactory() { }

	public:

        // returns true if all items from list are longer than VALID_LIMIT
		static bool isValid(QList<QString> list);
		static QNetworkReply::NetworkError downloadFileToQString(const QString &url,
																 QByteArray *output,
																 int timeout,
																 bool auth = false,
																 QList<QString> data = QList<QString>());

        // conversions
        static bool qstrToBool(const QString &value);
        static RssgTypes::FeedType  intToFeedType(int value);
        static RssgTypes::FeedType qstrToFeedType(const QString &string);
        static QString feedTypeToQstring(const RssgTypes::FeedType &type);

        // rss parsing & other stuff
        static QString parseDate(const QString &dateString);
		static bool isntInRssFeed(const QDomElement &node, RssFeed *feed);
		static bool isntInAtomFeed(const QDomElement &node, RssFeed *feed);

		static void parseAsRss(const QString &array, RssFeed *feed);
		static void parseAsAtom(const QString &array, RssFeed *feed);

		static RssgTypes::FeedType guessFeed(const QString &link, QString *out,
											 bool auth = false,
											 QList<QString> data = QList<QString>());
		static void parseFeed(RssFeed *feed, int timeout);

};


#endif // RSSFACTORY_H
